package algotithm.leetcode.string.test1768;

/**
 * @author 25068
 * @Date 2021/4/24 22:33
 * @Title 1768. 交替合并字符串
 */
public class Solution {


    public static void main(String[] args) {
        String word1 = "abcd";
        String word2 = "efgh";
        Solution solution = new Solution();
        String s = solution.mergeAlternately(word1, word2);
        System.out.println(s);
    }

    public String mergeAlternately(String word1, String word2) {
        int len1 = word1.length();
        int len2 = word2.length();
        int index = 0;
        char[] ch = new char[len1 + len2];
        for (int i = 0; i  < len1 || i < len2; i++) {
            if (i < len1) {
                ch[index++] = word1.charAt(i);
            }
            if (i < len2) {
                ch[index++] = word2.charAt(i);
            }
        }
        return String.valueOf(ch);
    }

}
